import http from '../request/index'

/* export const getList = ({url,method='post',data={}}) =>{
    return http({
        url,
        method,
        data
    }).then(res=>{
       return  Promise.resolve(res)
    }).catch(err=>{
        return Promise.reject(err)
    })
} */

// 测试调一个接口，然后返回数据调另外一个接口
export const getList = async ({ url, method = 'post', data = {} }) => {
    const test1 = await http({
        url,
        method,
        data
    })
    console.log(test1,'修改前');
    if (test1.data[0]?.id) {
        const dealDataWithPopId = await http({
            url: '/api2',
            method: 'POST',
            data: {
                id: test1.data[0].id
            }
        })
        const { data } = dealDataWithPopId;
        // 深拷贝
        const newData = JSON.parse(JSON.stringify(test1))
        data.forEach((item,index)=>{
            if(newData.data[index]){
                newData.data[index].photo = item.photo;
            }
        })
        console.log(newData,'修改后');
        return newData;
    }
    // console.log(test1,'修改后');
    return test1;
}